package com.myteam.mystory.service;

import java.util.ArrayList;

import com.myteam.mystory.DAO.ChapterDAO;
import com.myteam.mystory.DAO.CreateDatabase;
import com.myteam.mystory.entity.ChapterEntity;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;

public class ChapterService {
	private final Context context;

	public ChapterService(Context context) {
		super();
		this.context = context;
	}
	
	public long insert_chapter(ChapterEntity chapterEntity){
		CreateDatabase createDb = new CreateDatabase(context);
		SQLiteDatabase db = createDb.open();
		ChapterDAO chapterDAO = new ChapterDAO(db);
		long result = chapterDAO.insert_chapter(chapterEntity);
		db.close();
		createDb.close();
		return result;
	}
	
	public ArrayList<ChapterEntity> getAllChapter() {
		CreateDatabase createDb = new CreateDatabase(context);
		SQLiteDatabase db = createDb.open();
		ChapterDAO chapterDAO = new ChapterDAO(db);
		ArrayList<ChapterEntity> list_chap = new ArrayList<ChapterEntity>();
		list_chap = chapterDAO.getAllChapter();
		db.close();
		createDb.close();
		return list_chap;
	}
	
	public long deleteTableChapter(){
		CreateDatabase createDb = new CreateDatabase(context);
		SQLiteDatabase db = createDb.open();
		ChapterDAO chapterDAO = new ChapterDAO(db);
		long result = chapterDAO.deletetablechapter();
		db.close();
		createDb.close();
		return result;
	}
}
